/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package se.sll.engagemangsindex.ejb;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import javax.ejb.Singleton;
import lombok.extern.slf4j.Slf4j;

/**
 * Singleton class for holding runtime configuration read from a properties
 * file.
 *
 * @author khaleddaham
 */
@Singleton
@Slf4j
public class ConfigurationHolder {

    private Properties properties = null;
    private boolean featureProcessNotification = true;
    private boolean featureMetrics = true;

    /**
     * By default we look for engagemangsindex.properties in our classpath.
     */
    public ConfigurationHolder() {
        try {
            properties = new Properties();
            InputStream settingsStream = this.getClass().getClassLoader().getResourceAsStream("engagemangsindex.properties");
            this.properties.load(settingsStream);
        } catch (IOException ex) {
            log.error("Unable to initialize configuration.", ex);
        }
    }

    /**
     * Used for testing.
     *
     * @param properties
     */
    ConfigurationHolder(Properties properties) {
        this.properties = properties;
    }

    /**
     *
     * @return
     */
    public String getServiceCatalogue() {
        return this.properties.getProperty("service.catalogue.url");
    }

    /**
     *
     * @return
     */
    public String getOwner() {
        return this.properties.getProperty("engagemangsindex.owner.hsaid");
    }

    /**
     *
     * @return
     */
    public String getVirtualService() {
        return this.properties.getProperty("virtual.service.url");
    }

    /**
     * Used to turn off/on outbound notifications 
     * @return 
     */
    public boolean hasFeatureProcessNotification() {
        return featureProcessNotification;
    }

    /**
     * Used to turn off/on metrics
     * @return 
     */
    public boolean hasFeatureMetrics() {
        return featureMetrics;
    }
}